<!--#include file="../nav/admin_top.php" -->
<style type="text/css">

.tables{
border-collapse:collapse;
color:#555555;
}
.tables th{
background-color:#E2F4C4;
}
.tables td,.tables th{
padding:5px;
vertical-align:top;
text-align:center;
border:1px solid #CCCCCC;
}

tr.on td{
background-color:#F3FDE3;
}
.opts a{
margin-left:10px;
}
.opts a:hover{
background-color:transparent!important;
color:#336699!important;
}

.indexs{
color:#FF3300;
font-size:1.2em;
font-weight:bold;
}

.mybtn {
background-color:#DDDDDD;
border:1px solid #AAAAAA;
color:#224466;
cursor:pointer;
margin-left:10px;
padding:1px 3px;
}
</style>  
<script type="text/javascript">
var types = {json_encode($rs)};
var listname = "{$listname}";
var key = "{$key}";
var url_return = '/admin_list/index';
var url_add = '/admin_list/add';
var url_del = '/admin_list/del';
var url_modify = '/admin_list/modify';


var nums=0;
$().ready(function(){
	showLoading();
	o2js.build('json');
	fnShowIndex();
	nums = types.length;
	
	$('#add_name').keypress(function(e){
		if(e.keyCode==13||e.keyCode==10){
			fnAdd();
		}
	}).focus(); 
});
/* 上移动 */
function fnToUp(id){
	var curteam = '#mytype_'+id;
	if($(curteam).prev().length == 0) return false;
	$(curteam).prev().before( $(curteam) );
	//$(curteam).effect("highlight");
	fnShowIndex();
}
/* 下移动 */
function fnToDown(id){
	var curteam = '#mytype_'+id;
	if($(curteam).next().length == 0) return false;
	$(curteam).next().after( $(curteam) );
 
	//$(curteam).effect("highlight");
	fnShowIndex();
}
/* 排序管理 */
function fnShowIndex(){
	var i=1;
	$('#mytypes tr').each(function(e){
		var tmp = i++;
		$(this).find('.indexs').html(tmp);
	});
}
/* 添加 */
function fnAdd(){
	var add_name = $.trim( $('#add_name').val() );
	if(add_name == ''){
		alert('请输入【'+listname+'】');
	  $('#add_name').focus();
		return false;
	}
	$('button').attr('disabled','disabled');
	$.post(
		url_add,
		{
			val:add_name,
			key:key
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success=='1'){
				window.location.reload();
			}
			$('button').attr('disabled','');
		}
	); 
}
/* 删除 */
function fnDel(id){
	fnConfirm({
		str:'删除本行数据?',
		func_true:function(){
			$('button').attr('disabled','disabled');
			$.post(
				url_del,
				{
					id:$('#id_'+id).val(),
					key:key
				},
				function(e){
					var ok = errorHandler(e);
					if(ok && ok.success=='1'){
						$('#mytype_'+id).remove();
						fnShowIndex();
					}
					$('button').attr('disabled','');
				}
			);
		}
	}); 
} 
/* 保存 */
function fnSave(){
	var objs = []; 
	for(var i=0; i<nums; i++){
		if(fnDom('mytype_'+i)){
			if($.trim($('#val_'+i ).val()) == ''){
				alert('请填写第 '+$('#mytype_'+i+' .indexs').html() + ' 行的'+listname+'！');
				return false;
			}
			var tmp  ={};
			tmp['show_index'] = $('#mytype_'+i+' .indexs').html();
			tmp['val'] = $.trim($('#val_'+i ).val());
			tmp['id'] = $.trim($('#id_'+i ).val());
			objs.push(tmp);
			
		}
	}
	if(objs.length == 0){
		alert('没有任何可保存数据，请先添加！');
		return false;
	} 
	$('button').attr('disabled','disabled');
	$.post(
		url_modify,
		{
			objs:JSON.encode(objs),
			key:key
		},
		function(e){
			var ok = errorHandler(e);
			if(ok && ok.success == '1'){
				window.location.reload();
			} 
			$('button').attr('disabled','');
		}
	);
} 



</script>

<div class="titleDiv">
	<div class="titleCaption">
		<span class="captionSpan">会员静态字典 - {$listname}</span>
		<span class="totalSpan"> <label id="captionNum"></label> </span>
	</div>
</div>

<div class="blockdiv">
	<div class="titlediv">新增</div>
	{$listname}：<input type="text" class="textBox" id="add_name" maxlength="50" /> <button class="mybtn" onclick="fnAdd()">添加</button>
</div> 
  

<div> 
	 <table class="tables" >
	 		<thead>
				<tr>
					<th style="width:50px">序号</th>
					<th style="width:150px">{$listname}</th>
					<th style="width:180px">操作</th>
				</tr>
			</thead>
			<tbody id="mytypes">
				<?PHP		
				if(count($rs) > 0 )			
				foreach($rs as $k=>$v){
					echo '
						<tr id="mytype_'.$k.'"   >
							<td class="indexs">'.($k+1).'</td>
							<td>
								<input type="hidden"  id="id_'.$k.'" value="'.$v['id'].'" />
								<input type="text" class="textBox" id="val_'.$k.'"  value="'.$v['val'].'" />
							</td>
							<td class="opts">
								<a href="javascript:void(0)" onclick="fnToUp('.$k.')"><img src="/misc/images/home/totop.gif" /> 上移</a>
								<a href="javascript:void(0)" onclick="fnToDown('.$k.')"><img src="/misc/images/home/tobottom.gif" /> 下移</a>
								<a href="javascript:void(0)" onclick="fnDel('.$k.')"><img src="/misc/images/home/del.gif" /> 删除</a>
							</td>
						</tr> 					
					';
				}
				?> 
			</tbody>
	 </table>
</div>
<div class="button_div">
	<button class=" " onclick="fnSave()">保 存</button>
	<span class="gray">或</span> 
	<button class=" " onclick="jumpTo(url_return)">返 回</button>
</div>
 
<!--#include file="../nav/admin_bottom.php" -->